#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 305;
int n, A[MAXN], F[MAXN][MAXN][MAXN], Ans;
int main(){
  freopen("build.in", "r", stdin);
  freopen("build.out", "w", stdout);
  cin.tie(nullptr)->sync_with_stdio(false);
  cin >> n;
  for(int i = 1; i <= n; i++) cin >> A[i];
  memset(F, 0x3F, sizeof(F)), Ans = F[0][0][0], F[1][n][1] = 0;
  for(int k = n; k; k--) for(int i = 1; i + k - 1 <= n; i++){
    int j = i + k - 1;
    for(int x = 1; x <= i + n - j; x++){
      int y = k + x - 1;
      F[i + 1][j][x + 1] = min(F[i + 1][j][x + 1], F[i][j][x] + (A[i] != x));
      F[i + 1][j][x    ] = min(F[i + 1][j][x    ], F[i][j][x] + (A[i] != y));
      F[i][j - 1][x + 1] = min(F[i][j - 1][x + 1], F[i][j][x] + (A[j] != x));
      F[i][j - 1][x    ] = min(F[i][j - 1][x    ], F[i][j][x] + (A[j] != y));
    }
  }
  for(int i = 0; i <= n; i++) for(int x = 1; x <= n + 1; x++) Ans = min(Ans, F[i + 1][i][x]);
  cout << Ans << '\n';
  return 0;
}
